package com.gxkj.drm.enums;

/**
 * 用户等级
 * Created by changxiangyang on 2017/9/27.
 */
public enum RoleType {

    ROOT(0, "超级管理员"),

    ADMIN(1, "管理员"),

    USER(2, "用户");

    private int level;
    private String name;

    RoleType(int level, String name) {
        this.level = level;
        this.name = name;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean havePermission(RoleType roleType) {
        return this.level <= roleType.level;
    }

    public static RoleType find (int level) {
        for (RoleType r : RoleType.values()) {
            if (r.getLevel() == level) {
                return r;
            }
        }
        return null;
    }
}
